package com.waimai.app.qa.tool;

import java.io.File;
import java.io.FileFilter;
   
/**
 * ExtensionFileFilter,文件过滤类
 * @author AiHui
 */
public class ExtensionFileFilter implements FileFilter {
	private String extension;
	
	/**
	 * 判断某文件是否属于特定类型的文件。
	 * @param extension
	 */
	public ExtensionFileFilter(String extension){
		this.extension = extension;
	}
	
	public boolean accept(File file) {
		if(file.isDirectory()){
			return false;
		}
		
		String name = file.getName( );
		int index = name.lastIndexOf(".");
		
		if(index == -1){
			return false;
		}else if(index == name.length( )-1){
			return false;
		}else{
			return this.extension.equals(name.substring(index+1));
		}
	}
}